package com.pyg.manager.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pyg.manager.service.BrandService;
import com.pyg.mapper.BrandMapper;
import com.pyg.pojo.TbBrand;
import com.pyg.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {

    // 注入mapper接口代理对象
    @Autowired
    private BrandMapper brandMapper;

    /**
     * 查询所有品牌数据
     */
    @Override
    public List<TbBrand> findAll() {
        return brandMapper.findAll();
    }

    /**
     * 品牌分页查询展示
     */
    @Override
    public PageResult findByPage(Integer page, Integer rows) {
        // 设置分页查询
        PageHelper.startPage(page, rows);
        // 分页查询
        Page<TbBrand> pageInfo = (Page<TbBrand>) brandMapper.findAll();
        // 返回
        return new PageResult(pageInfo.getTotal(), pageInfo.getResult());
    }

    /**
     * 新增品牌
     */
    @Override
    public void add(TbBrand brand) {
        brandMapper.insert(brand);
    }


    /**
     * 通过id查询品牌数据
     */
    @Override
    public TbBrand findById(Long id) {
        return brandMapper.findById(id);
    }

    /**
     * 修改品牌数据
     */
    @Override
    public void updateByPrimaryKey(TbBrand brand) {
        brandMapper.updateByPrimaryKey(brand);
    }

    /**
     * 删除品牌数据
     */
    @Override
    public void delete(long[] ids) {
        for (long id : ids) {
            brandMapper.delete(id);
        }
    }

}
